package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.constant.MessageConstant;
import com.itheima.dao.SetmealMapper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @version V1.0
 * @author: ljx
 * @date: 2020/01/13 16:07
 * @description:
 */
@Service(interfaceClass = SetMealService.class)
@Transactional
public class SetMealServiceImpl implements SetMealService {

    @Autowired
    private SetmealMapper setmealMapper;


    @Override
    public Result add(Setmeal setmeal) {
        setmealMapper.addSetmealBasicMsg(setmeal);
        setmealMapper.addRelationBetweenSetmealAndCheckgroup(setmeal.getId(), setmeal.getCheckgroupIds());
        return new Result(true, MessageConstant.ADD_SETMEAL_SUCCESS);
    }

    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        Page page = PageHelper.startPage(pageBean.getCurrentPage(), pageBean.getPageSize());

        List<Setmeal> setmealList = setmealMapper.findPage(pageBean.getQueryString());
        return new PageResult(page.getTotal(),setmealList);
    }
}
